package product.dto;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import product.type.ExerciseType;

import java.io.Serializable;
import java.util.Date;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class SportsDto implements Serializable {
    private int id;
    private int userId;
    private String username;
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date lastWorkoutDate;
    private int totalWorkouts;
    private float totalCaloriesBurned;

    // 构造函数
    public SportsDto(int userId, String username) {
        this.userId = userId;
        this.username = username;
        this.totalWorkouts = 0;
        this.totalCaloriesBurned = 0.0f;
    }

    // 添加一次锻炼
    public void addWorkout(ExerciseType exerciseType, float durationInHours) {
        float caloriesBurned = exerciseType.getCaloriesPerHour() * durationInHours;
        this.totalWorkouts++;
        this.totalCaloriesBurned += caloriesBurned;
        this.lastWorkoutDate = new Date();
    }

    // 获取用户信息
    public String getUserInfo() {
        return String.format("User: %s, Workouts: %d, Calories Burned: %.2f",
                username, totalWorkouts, totalCaloriesBurned);
    }
}
